import { ElMessageBox } from 'element-plus'

import { ElMessageBoxOptions } from 'element-plus/lib/el-message-box/src/message-box.type'

/**
 * 弹出框的封装
 * @param options
 */
export const useConfirm = (options: ElMessageBoxOptions, success?: Function, error?: Function) => {
  const defaultOptions: ElMessageBoxOptions = {
    title: '提示',
    showCancelButton: true,
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    customClass: 'cofirm-box cofirm-box--large',
    iconClass: 'el-icon-warning-outline',
    type: 'warning',
  }

  const mergeOptions: ElMessageBoxOptions = {
    ...defaultOptions,
    ...options,
  }

  console.log('mergeOptions:', mergeOptions)

  ElMessageBox(mergeOptions)
    .then(() => {
      success && success()
    })
    .catch(() => {
      error && error()
    })
}
